
from fastapi import FastAPI
from starlette.responses import HTMLResponse

import util.util

app = FastAPI()


@app.get("/", response_class=HTMLResponse)
async def root():
    return """
    <!DOCTYPE html>
    <html>
    <head>
        <title>欢迎页</title>
        <style>
            body {
                font-family: Arial, sans-serif;
                text-align: center;
                margin-top: 100px;
            }
            h1 {
                color: #333;
            }
            .container {
                max-width: 800px;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="container">
            <h1>此服务提供了将exel解析为JSON格式的数据接口</h1>
          
            <p>当前时间: <span id="time"></span></p>
        </div>

        <script>
            document.getElementById('time').textContent = new Date().toLocaleString();
        </script>
    </body>
    </html>
    """


@app.get("/Analysis")
async def Analysis(url: str):

    return util.util.download_and_read_excel(url)


if __name__ == '__main__':
    app.run(host='0.0.0.0', port=9999)  # 允许外部访问，端口设为 8080